package cruciverba.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import cruciverba.model.Verifica;

public class VerifyButton extends JButton{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private JTextArea area;
	private Verifica verifica;
	private JTextField field;
	
	public VerifyButton(JTextArea area, Verifica verifica, JTextField field) {
		super();
		this.area = area;
		this.verifica = verifica;
		this.field = field;
		SetButton();
	}

	private void SetButton() {
		this.setText("Verifica");
		
		this.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				area.setText(null);
				field.setEnabled(false);
				try {
					verifica.setResultVerifica(field.getText());

				} catch (Exception e1) {
					area.setText(e1.getMessage());
				}
			}
		});
	}
	
	
	
	

}
